package com.huluobo.a2207mmonthdemo.adapter;

import android.animation.ObjectAnimator;
import android.view.View;
import android.view.animation.LinearInterpolator;
import android.widget.ImageView;

import androidx.annotation.NonNull;

import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.huluobo.a2207mmonthdemo.R;
import com.huluobo.a2207mmonthdemo.utils.ImageUtils;
import com.huluobo.base.bean.VideoBeanResult;
import com.shuyu.gsyvideoplayer.video.StandardGSYVideoPlayer;

/**
 * Created by LC on 2024/10/8.
 */
public class MultiVideoAdapter extends BaseMultiItemQuickAdapter<VideoBeanResult.VideoBean, BaseViewHolder> {
    public MultiVideoAdapter() {
        addItemType(0, R.layout.item_videos);
        addItemType(1, R.layout.item_video_live);
        addItemType(2, R.layout.item_video_full);
    }

    @Override
    protected void convert(@NonNull BaseViewHolder baseViewHolder, VideoBeanResult.VideoBean videoBean) {
        StandardGSYVideoPlayer player = baseViewHolder.getView(R.id.item_videos_gsyPlayer);
        player.getBackButton().setVisibility(View.GONE);
        player.setUp(videoBean.getVideopath(), true, "");

        baseViewHolder.setText(R.id.item_videos_address_tv, videoBean.getAddress() + "");
        baseViewHolder.setText(R.id.item_videos_authname_tv, videoBean.getAuthname());
        baseViewHolder.setText(R.id.item_videos_caption_tv, videoBean.getCaption());
        baseViewHolder.setText(R.id.item_videos_pao_tv, videoBean.getAuthname() + "的原创作品");

        if (videoBean.getType() == 0 || videoBean.getType() == 2) {
            ImageUtils.getInstance().loadCircleImage(getContext(), videoBean.getHeadpath(),
                    baseViewHolder.getView(R.id.item_videos_header_iv));
            if (videoBean.getGuanzhu() == 0) {
                baseViewHolder.getView(R.id.item_videos_add_iv).setVisibility(View.VISIBLE);
            } else {
                baseViewHolder.getView(R.id.item_videos_add_iv).setVisibility(View.GONE);
            }

            if (videoBean.getDianzan() == 0) {
                baseViewHolder.setImageResource(R.id.item_videos_like_iv, R.drawable.ic_xihuan);
            } else {
                baseViewHolder.setImageResource(R.id.item_videos_like_iv, R.drawable.ic_xihuanred);
            }

            baseViewHolder.setText(R.id.item_videos_like_count_tv, videoBean.getLike_count() >= 10000 ?
                    videoBean.getLike_count() / 10000 + "W" : videoBean.getLike_count() + "");
            baseViewHolder.setText(R.id.item_videos_comment_count_tv, "3.5W");
            baseViewHolder.setText(R.id.item_videos_collect_count_tv, "3.2W");
            baseViewHolder.setText(R.id.item_videos_share_count_tv, "2.5W");
            ImageView musicPlayerView = baseViewHolder.getView(R.id.item_videos_music_player_iv);
            ImageUtils.getInstance().loadCircleImage(getContext(), videoBean.getHeadpath(), musicPlayerView);

            ObjectAnimator animator = ObjectAnimator.ofFloat(musicPlayerView, "Rotation", 0, 360);
            animator.setDuration(3000);
            animator.setRepeatCount(-1);
            animator.setInterpolator(new LinearInterpolator());
            animator.start();
        }
    }
}
